import logging

# 设置默认打印等级
logging.basicConfig(level=logging.INFO)

# 创建日志对象
logger = logging.getLogger("MyLogger")
# 设置打印等级
logger.setLevel(logging.ERROR)
# 打开文件句柄处理器,用于输出日志
handle = logging.FileHandler('mylog.log')
# 创建一个日志格式化对象pytest
formatter = logging.Formatter('%(asctime)s %(levelname)s [%(name)s] [%(filename)s (%(funcName)s:%(lineno)d)] - %(message)s')
# 将格式化对象设置到处理器上
handle.setFormatter(formatter)
# 将处理器添加到日志记录上
logger.addHandler(handle)


logger.debug("This is a debug log")
logger.info("This is a info log")
logger.warning("This is a warning log")
logger.error("This is a error log")
logger.critical("This is a critical log")
